package backend.service.base;

import backend.model.base.DBModel;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collection;

public abstract class DBModelServiceImpl<DBM extends DBModel> implements DBModelService<DBM> {

    @Autowired
	protected DBModelDao<DBM> dbModelDao;

    @Override
    abstract public Class<DBM> getEntityClass();

    @Override
    public DBM getDbModelById(int id) {
        return dbModelDao.getById(getEntityClass(), id);
    }

    @Override
    public void saveOrUpdateDBModel(DBM dbModel) {
        dbModelDao.saveOrUpdate(dbModel);
    }

    @Override
    public void bulkSaveOrUpdateDBModels(Collection<DBM> dbModelCollection) {
        dbModelDao.bulkSaveOrUpdate(dbModelCollection);
    }

	@Override
    public void saveDBModel(DBM dbModel) {
        dbModelDao.saveOrUpdate(dbModel);
	}

    @Override
    public void bulkSaveDBModels(Collection<DBM> dbModelCollection) {
        dbModelDao.bulkSave(dbModelCollection);
    }

	@Override
    public void updateDBModel(DBM dbModel) {
        dbModelDao.saveOrUpdate(dbModel);
	}

    @Override
    public void deleteDBModel(DBM dbModel) {
        dbModelDao.delete(dbModel);
    }

    @Override
    public void bulkDeleteDBModels(Collection<DBM> dbModelCollection) {
        dbModelDao.bulkDelete(dbModelCollection);
    }
}
